package com.sdy.healthcode.h5.controller;

import com.sdy.common.model.Response;
import com.sdy.healthcode.h5.config.WxConfig;
import com.sdy.mvc.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
@RequestMapping("/wechat")
@Api(tags = "微信接口")
@Slf4j
public class WechatController extends BaseController {
    /**
     * 微信登录
     */
    @PostMapping("/createJsSdkSigniture")
    @ApiOperation(value = "JS-SDK使用权限签名")
    @ApiImplicitParam(value = "扫码页面地址", name = "url", required = true)
    public Response createJsSdkSigniture(String url) throws UnsupportedEncodingException {
        url = URLDecoder.decode(url, "utf-8");
        log.info("CreateJsSdkSigniture for: {}", url);
        return Response.success(WxConfig.createJsSdkSigniture(url));
    }
}
